<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="admin/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="admin/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>

<p th:text="${postNo}" style="display: none" id="EditPostNo"></p>


<form class="layui-form layuimini-form" id="up_form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label required">贴子标题</label>
        <div class="layui-input-block">
            <input type="text" name="postTitle" id="postTitle" lay-verify="required" lay-reqtext="贴子标题不能为空" placeholder="请输入贴子标题" value="" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label required">贴子发布者</label>
        <div class="layui-input-block">
            <input type="text" name="userNo" id="userNo" value="" class="layui-input" placeholder="请输入贴子发布者">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">贴子所属板块</label>
        <div class="layui-input-block">
            <input type="text" name="communityNo" id="communityNo" lay-verify="required" lay-reqtext="贴子所属板块不能为空" placeholder="请输入贴子所属板块" value="" class="layui-input">
        </div>
    </div>

   <!-- <div class="layui-form-item">
        <label class="layui-form-label required">贴子发布状态</label>
        <div class="layui-input-block">
            <input type="text" name="postStatus" id="postStatus" placeholder="请选择贴子发布状态" value="" class="layui-input">
        </div>
    </div>-->
    <div class="layui-form-item">
        <label class="layui-form-label required">贴子发布状态</label>
        <div class="layui-input-block">
            <select name="postStatus" id="postStatus" lay-filter="aihao">
                <option value="1">审核中</option>
                <option value="0">下架</option>
                <option value="2">发布中</option>
            </select>
            <div class="layui-unselect layui-form-select">

                  <dl class="layui-anim layui-anim-upbit" style="">
                      <dd lay-value="1" id="shz">审核中</dd>
                      <dd lay-value="0" class="" id="xj">下架</dd>
                      <dd lay-value="2" class="" id="fbz">发布中</dd>
                  </dl>
            </div>
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">贴子发布时间</label>
        <div class="layui-input-block">
            <input type="text" name="postTime" id="postTime" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">贴子点击量</label>
        <div class="layui-input-block">
            <input type="text" name="postClickNumber" id="postClickNumber" placeholder="请输入贴子点击量" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">贴子点赞量</label>
        <div class="layui-input-block">
            <input type="text" name="postLikeNumber" id="postLikeNumber" placeholder="请输入贴子点赞量" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">贴子收藏量</label>
        <div class="layui-input-block">
            <input type="text" name="postCollectionNumber" id="postCollectionNumber" placeholder="请输入贴子收藏量" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">贴子评论量</label>
        <div class="layui-input-block">
            <input type="text" name="postCommentNumber" id="postCommentNumber" placeholder="请输入贴子评论量" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">贴子最后更新时间</label>
        <div class="layui-input-block">
            <input type="text" name="endingTime" id="endingTime" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label required">贴子内容</label>
        <div class="layui-input-block">
            <input type="text" name="postContent" id="postContent" placeholder="请输入贴子内容" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</form>
<script src="admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate,
            upload = layui.upload;
            $ = layui.$;

        var selectPostStatus='';

        //日期
        laydate.render({
            elem: '#endingTime'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#postTime'
            ,type: 'datetime'
        });
        /*获取选中的贴子数据*/
        $.ajax({
            type:'get',
            url:'post/queryPost',
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("token", window.sessionStorage.getItem("token"));
            },
            async:false,
            data:{postNo:$('#EditPostNo').text()},
            success:(res)=>{

                if(res.data.post != null){

                    var communityData = res.data.post;
                    selectPostStatus = communityData.postStatus;
                    // var postTime = communityData.postTime.split('T');
                    // var endingTime = communityData.endingTime.split('T');
                    $('#postTitle').val(communityData.postTitle);
                    $('#userNo').val(communityData.userNo);
                    $('#communityNo').val(communityData.communityNo);
                   /* $('#postStatus').val(communityData.postStatus);*/
                    $('#postTime').val(communityData.postTime);
                    $('#postClickNumber').val(communityData.postClickNumber);
                    $('#postLikeNumber').val(communityData.postLikeNumber);
                    $('#postCommentNumber').val(communityData.postCommentNumber);
                    $('#postContent').val(communityData.postContent);
                    $('#postCollectionNumber').val(communityData.postCollectionNumber);
                    $('#endingTime').val(communityData.endingTime);
                }
            },
            error:(err)=>{

            }
        });



        //监听提交
        form.on('submit(formDemo)', function(data){
         ////   var date = new Date();

            console.log(data)
            subData = {
                postTitle:data.field.postTitle.toString(),
                postNo:$('#EditPostNo').text(),
                userNo:data.field.userNo.toString(),
                communityNo:data.field.communityNo.toString(),
                postStatus:data.field.postStatus,
                postTime:data.field.postTime.toString(),
                postClickNumber:data.field.postClickNumber.toString(),
                postLikeNumber:data.field.postLikeNumber.toString(),
                postCommentNumber:data.field.postCommentNumber.toString(),
                postContent:data.field.postContent.toString(),
                endingTime:data.field.endingTime.toString()
            }
            $.ajax({
                type:'get',
                url:'post/modifyPost',
                beforeSend: function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("token", window.sessionStorage.getItem("token"));
                },
                data:subData,
                success:(res)=>{
                    if(res.success === true){
                        alert('修改成功');
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        parent.location.href = 'toPostIndex';
                    }else{
                        alert('修改失败')
                    }
                },
                error:(err)=>{

                }
            });
            return false;
        });


    });
</script>
</body>
</html>